from urllib.request import urlopen

url = 'http://www.baidu.com'
resp = urlopen(url)
result_str = resp.read().decode('utf-8')
# 打印抓取到的源代码
print(result_str)
# 将源代码写入本地html文件
with open('mybaidu.html', mode='w') as f:
    f.write(result_str)
print('over')
